<?php
namespace app\api\controller\m2979\auto;

use think\Db;
use service\ApiReturn;
use app\api\controller\Base;
use app\member\service\MemberCache;


class Freeshouji extends Base {
                
/**
 *  查询手机
 *@create_time  2023-12-08 15:17:05
 */ 
public function get_shouji($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freeshouji.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freeshouji.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freeshouji.is_del', '=', 0]; 
 
    $select_info = array (
); 
	$dataList = Db::table('lb_free_shouji')
		->alias('freeshouji')
		->field("freeshouji.mingcheng,freeshouji.shengshiqu1,freeshouji.shengshiqu,freeshouji.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
		$area = \app\common\model\Area::where([["region_code", "in", $infodataList['shengshiqu1']]])->column("name");
		if (count($area) > 0) {
			$infodataList['shengshiqu1_area'] = implode(',', $area);
		}else{
			$infodataList['shengshiqu1_area'] = '';
		}
		$area = \app\common\model\Area::where([["region_code", "in", $infodataList['shengshiqu']]])->column("name");
		if (count($area) > 0) {
			$infodataList['shengshiqu_area'] = implode(',', $area);
		}else{
			$infodataList['shengshiqu_area'] = '';
		}
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
            
/**
 *  查询手机3
 *@create_time  2023-12-08 15:17:00
 */ 
public function get_shouji4($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freeshouji.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freeshouji.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freeshouji.is_del', '=', 0]; 
 
    $select_info = array (
); 
	$dataList = Db::table('lb_free_shouji')
		->alias('freeshouji')
		->field("freeshouji.mingcheng,freeshouji.shengshiqu1,freeshouji.shengshiqu,freeshouji.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
		$area = \app\common\model\Area::where([["region_code", "in", $infodataList['shengshiqu1']]])->column("name");
		if (count($area) > 0) {
			$infodataList['shengshiqu1_area'] = implode(',', $area);
		}else{
			$infodataList['shengshiqu1_area'] = '';
		}
		$area = \app\common\model\Area::where([["region_code", "in", $infodataList['shengshiqu']]])->column("name");
		if (count($area) > 0) {
			$infodataList['shengshiqu_area'] = implode(',', $area);
		}else{
			$infodataList['shengshiqu_area'] = '';
		}
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}
            
/**
 *  查询手机
 *@create_time  2024-01-19 15:06:03
 */ 
public function get_shouji3($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freeshouji.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freeshouji.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freeshouji.is_del', '=', 0]; 
 
    $select_info = array (
  'xuanxiang' => 
  array (
    1 => 'A',
    2 => 'B',
  ),
  'freeyonghu_tianqi' => 
  array (
    1 => '晴天',
    2 => '阴天',
    3 => '多云',
  ),
); 
	$dataList = Db::table('lb_free_shouji')
		->alias('freeshouji')
		->leftjoin('lb_free_flow freeflow', 'freeflow.aid = freeshouji.freeflowWenben_1_id')
		->leftjoin('lb_free_yonghu freeyonghu', 'freeyonghu.aid = freeshouji.freeyonghu_id')
		->field("freeshouji.aid,freeshouji.shengshiqu,freeshouji.mingcheng,freeshouji.freeflowWenben_1 as freeflowWenben_1,freeshouji.shijian,freeshouji.qixian,freeshouji.wenjian,freeshouji.zhengshu,freeshouji.shuzi,freeshouji.jisuan,freeshouji.jine,freeshouji.tupian,freeshouji.shipin,freeshouji.xuanxiang,freeshouji.dancengduoxuan,freeyonghu.xingming as freeyonghu_xingming,freeshouji.duoxuan,freeyonghu.tianqi as freeyonghu_tianqi,freeshouji.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
		$area = \app\common\model\Area::where([["region_code", "in", $infodataList['shengshiqu']]])->column("name");
		if (count($area) > 0) {
			$infodataList['shengshiqu_area'] = implode(',', $area);
		}else{
			$infodataList['shengshiqu_area'] = '';
		}
			$infodataList['shijian'] = $infodataList['shijian']? date('Y-m-d H:i:s', $infodataList['shijian']): '';
			$infodataList['wenjian'] = get_pass_files_url($infodataList['wenjian'],1);
			$infodataList['tupian']  = get_file_url($infodataList['tupian']);
			$infodataList['shipin']  = [get_file_url($infodataList['shipin'])];
			$infodataList['xuanxiang_name'] = $select_info['xuanxiang']["{$infodataList['xuanxiang']}"] ?? '';
			$infodataList['freeyonghu_tianqi_name'] = $select_info['freeyonghu_tianqi']["{$infodataList['freeyonghu_tianqi']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

}